import geopandas as gpd


# define correspondence for recoding PVWater categories
# across years for consistency
# in the format of {from: to}
recode_dict = {
    1 : 'Developed',
    2 : 'Cropland',
    3 : 'Grass/Shrub',
    4 : 'Tree Cover',
    5 : 'Water',
    6 : 'Wetland',
    7 : 'Ice/Snow',
    8 : 'Barren',
}

recode_dict_pvwater = {
    'Grass/Shrub' : 'Natural',
    'Tree Cover' : 'Natural',
    'Wetland' : 'Natural',
}



def load(year, file_name):
    """Loads data.

    Args:
        year (int): The year of interest.
        file_name (str): The path to input file.

    Returns:
        df (geopandas.GeoDataFrame): The loaded dataset.
    """
    df = (gpd.read_file(file_name))
          #.filter(items=[col_name[year], 'geometry']))
    # rename for consistency
    df.columns = ['lcmap', 'geometry']
    # recode pv water categories
    df.loc[:, 'lcmap'] = df['lcmap'].replace(recode_dict)
    df.loc[:, 'lcmap'] = df['lcmap'].replace(recode_dict_pvwater)
    # drop empty and missing
    df = df.loc[~(df['geometry'].is_empty | df['geometry'].isna()), :]
    return df
